package springboot.example;


import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import springboot.example.interceptor.TestInterceptor;

@SpringBootApplication()
@RestController
public class Application {

   @RequestMapping("/")
    String home(){
        return "hello";
    }

    public static void main(String[] args){
        SpringApplication.run(Application.class,args);
    }


    //mvc控制器
    @Configuration
    static class WebMvcConfigurer extends WebMvcConfigurerAdapter {
        //增加拦截器
        public void addInterceptors(InterceptorRegistry registry){
            registry.addInterceptor(new TestInterceptor())    //指定拦截器类
                    .addPathPatterns("/hello");        //指定该类拦截的url
        }
    }

}
